package ssm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ssm.model.entity.Video;
import ssm.model.entity.VideoBanner;
import ssm.service.VideoService;
import ssm.utils.BaseCache;
import ssm.utils.JsonData;

import java.util.List;

/**
 * 1、前端调用接口流程；
 * 1、http://localhost:8080/api/v1/pub/video/list，调用了 VideoController 中的方法 videoService.listVideo()
 * 2、通过videoService.listVideo() 调用了实现类 VideoServiceImpl，这个实现类需要添加注解
 * 3、VideoServiceImpl实现调用了 VideoMapper，这个里面定义了与XML配对的方法，这个可以不用添加注解
 * 4、VideoMapper通过方法名去VideoMapper.xml里面找对应ID标签的sql，然后执行数据库
 * 5、通过VideoController中的注解@RestController 将数据库的数据以json格式返回给前端
 */
@RestController
@RequestMapping("/api/v1/pub/video")
public class VideoController {
    @Autowired
    private VideoService videoService;



    @RequestMapping("list")
    public JsonData listVideo() {

        List<Video> videos = videoService.listVideo();
        return JsonData.buildSuccess(videos);
    }


    @GetMapping("list_banner")
    public JsonData indexBanner() {

        List<VideoBanner> bannerList = videoService.listBanner();

        return JsonData.buildSuccess(bannerList);
    }


    @GetMapping("find_detail_by_id")
    public JsonData findDetailById(@RequestParam(value = "video_id", required = true) int videoId) {


        Video video = videoService.findDetailById(videoId);
        return JsonData.buildSuccess(video);

    }

}
